<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Shop_Highlight_Model extends MY_Model {
	public function __construct() {
		parent::__construct();
		$this->load->model('entity/shop_entity', 'Shop_Entity');
	}

	public function getList($aCol=array(), $all=false, $limit=0) {
		$select = '';
		if(count($aCol) > 0){
			$select = implode(',', $aCol);
		} else {
			$select = "
			a.id AS id, a.title AS title, a.slug AS slug, a.payment_method AS payment_method, a.details AS details,
			b.banner AS banner,
			c.phone AS phone, c.home_phone AS home_phone, c.email AS email,
			c.skype AS skype, c.address AS address, c.gmap AS gmap, c.image_folder AS image_folder
			";
		}
		$this->db->select($select, true);
		$this->db->from($this->table_shop_name         . ' AS a');
		$this->db->join($this->table_shop_setting_name . ' b', 'a.id=b.shop_id');
		$this->db->join($this->table_user_name         . ' c', 'a.user_id=c.id');
		if(!$all){
			$this->db->where('a.highlight_flg', ON);
			$this->db->where('a.active_flg', STATUS_ACTIVE);
			$this->db->where('a.deleted_at', null);
			$this->db->where('b.deleted_at', null);
			$this->db->where('c.deleted_at', null);
		}
		$this->db->order_by('a.created_at', 'DESC');
		if($limit!=0){
			$this->db->limit($limit, 0);
		}
		return $this->db->get()->result('Shop_Entity');
	}
}